package com.fei.jvmtest;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class AutoIncre {
    AtomicInteger atomicInteger = new AtomicInteger(0);

    Object instance = new Object();

    CountDownLatch latch = new CountDownLatch(10);

    // int index = 1;

    public void test() {
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    System.out.println(atomicInteger.incrementAndGet());
                    System.out.println(atomicInteger.incrementAndGet());
                    try {
                        Thread.sleep(5000);
                    }
                    catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    System.out.println("sssssssssssssssssssssssss");
                    latch.countDown();
                }
            }).start();
        }

        try {
            latch.await();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("done");
    }

    public static void main(String[] args) {
        new AutoIncre().test();
    }
}
